package com.ym.controller.management;

import com.github.pagehelper.PageInfo;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.shiro.ShiroUtil;
import com.ym.medical.domain.entity.RelevantCertRecordEntity;
import com.ym.medical.domain.vo.DoctorAuditRecordVo;
import com.ym.medical.service.IDoctorDetailSV;
import com.ym.medical.service.IRelevantCertRecordSV;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author: 张文博
 * @version: 2019年07月30日 8:54
 */
@Api(tags = "医生信息审核接口")
@Controller
@RequestMapping("/management/doctor")
@Validated
public class DoctorReviewController extends BaseController {

	@Autowired
	private IRelevantCertRecordSV iRelevantCertRecordSV;

	@Autowired
	private IDoctorDetailSV iDoctorDetailSV;

	@ApiOperation(value = "医生审核列表")
	@GetMapping("/cert/recordList")
	@ResponseBody
	public APIResponse<PageInfo<DoctorAuditRecordVo>> certRecordList(
			@ApiParam(name = "pageNo", value = "页码", required = true)
			@RequestParam(name = "pageNo", required = true, defaultValue = "1")
					int pageNo,
			@ApiParam(name = "limit", value = "每页数量", required = false)
			@RequestParam(name = "limit", required = false, defaultValue = "10")
					int limit,
			@ApiParam(name = "auditStatus", value = "审核状态", required = false)
			@RequestParam(name = "auditStatus", required = false, defaultValue = "01")
					String auditStatus,
			@ApiParam(name = "auditRecordVo", value = "其中certType 01 身份审核,02 资质", required = false)
					DoctorAuditRecordVo auditRecordVo) {
		auditRecordVo.setAuditStatus(auditStatus);
		PageInfo<DoctorAuditRecordVo> certRecordList = iDoctorDetailSV.certRecordList(pageNo, limit, auditRecordVo);
		return successData(certRecordList);
	}

	@ApiOperation(value = "医生审核图片")
	@GetMapping("/imageShow")
	@ResponseBody
	public APIResponse<RelevantCertRecordEntity> imageShow(
			@ApiParam(name = "id", value = "审核记录id", required = true) @RequestParam Long id,
			@ApiParam(name = "type", value = "查询类型 01身份 02 资质", required = true) @RequestParam String type) {
		RelevantCertRecordEntity certRecords = iRelevantCertRecordSV.selectById(id);
		return successData(certRecords);
	}

	@ApiOperation(value = "医生审核")
	@PostMapping("/doctorReview")
	@ResponseBody
	public APIResponse<RelevantCertRecordEntity> doctorReview(
			@ApiParam(name = "certRecord", value = "审核对象体", required = true)
			@RequestBody RelevantCertRecordEntity certRecord) {
		Long currId = ShiroUtil.getLoginId();
		certRecord.setAuditPerson(currId);
		int rows = iRelevantCertRecordSV.doctorReview02(certRecord);
		if (rows == 0) {
			return successMsg("操作失败");
		} else {
			return successMsg("操作成功");
		}
	}
}
